﻿using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using System.Data.SqlClient;

namespace DISPLAY_CLIENT
{
    /// <summary>
    /// InfoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class InfoWindow : Window
    {
        public InfoWindow(string cardno)
        {
            InitializeComponent();
            lb_cardno.Content = cardno;
            SqlDataReader reader = DB_SQLServer.ExecuteReader(string.Format("SELECT s.[StaffNo],s.[StaffName],(SELECT [DEPTNAME] FROM [SYS_DEPT] WHERE [SYS_DEPT].[DEPTID] = s.[DeptID]),(SELECT [TYPEJOBNAME] FROM [T_SM_TypeJob] WHERE [T_SM_TypeJob].[TYPEJOBID] = s.[TYPEJOB]),(SELECT [PositionsName] FROM [T_SM_Position] WHERE [T_SM_Position].[PositionsID] = s.[PositionsID]),s.[StaffTel],s.[Mobile],s.[StaffPhotoPath] FROM [T_JC_Tag] t INNER JOIN [T_SM_Staff] s ON t.[StafffID] = s.[StaffID] WHERE t.[TagMac] = '{0}'", cardno));
            if (reader.Read())
            {
                lb_staffno.Content = reader[0].ToString();
                lb_name.Content = reader[1].ToString();
                lb_org.Content = reader[2].ToString();
                lb_job.Content = reader[3].ToString();
                lb_job_lev.Content = reader[4].ToString();
                lb_tel.Content = reader[5].ToString();
                lb_mobile.Content = reader[6].ToString();
                img_photo.Source = new BitmapImage(new Uri(MainWindow.GetPhoto(reader[7].ToString().Replace('\\', '/')), UriKind.RelativeOrAbsolute));
            }
            else
            {
                lb_name.Content = "未知";
            }
            reader.Close();
        }

        private void Border_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }

        private void btn_close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
